<style>
    #add {
        padding: 20px 25px 25px 0;
    }

    #add .layui-treeSelect .ztree li a, .ztree li span {
        margin: 0 0 2px 3px !important;
    }
</style>
<div class="layui-fluid" id="add">
    <form class="layui-form" action="" lay-filter="course-update-form">
        <div class="layui-form-item">
            <label class="layui-form-label febs-form-item-require">实验名称</label>
            <div class="layui-input-block">
                <input type="text" name="projectId" lay-verify="required" class="layui-input" hidden>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label febs-form-item-require">实验名称</label>
            <div class="layui-input-block">
                <input type="text" name="projectName" lay-verify="required" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">所属实验课程</label>
            <div class="layui-input-block">
                <input type="text" name="courseName"  th:value=${project.courseName}   id="experiment_table" placeholder="请选择实验课程" lay-filter="experiment_table" class="layui-input">
                <input type="hidden" id="courseId">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">实验描述</label>
            <div class="layui-input-block">
                <input type="hidden" name="remark" id="remark">
                <div id="editor">
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label febs-form-item-require">状态：</label>
            <div class="layui-input-block">
                <input type="radio" name="state" value="1" title="有效" checked="">
                <input type="radio" name="state" value="0" title="禁用">
            </div>
        </div>

        <div class="layui-form-item febs-hide">
            <button class="layui-btn" lay-submit="" lay-filter="user-add-form-submit" id="submit"></button>
            <button type="reset" class="layui-btn" id="reset"></button>
        </div>
    </form>
</div>
<script type="text/javascript" th:src="@{febs/lay/extends/wangEditor.min.js}"></script>
<script data-th-inline="javascript">
    layui.use(['febs', 'form', 'tableSelect', 'validate'], function () {
        var $ = layui.$,
            febs = layui.febs,
            layer = layui.layer,
            form = layui.form,
            $view = $('#add'),
            project = [[${project}]],
            tableSelect = layui.tableSelect,
            validate = layui.validate;

        form.verify(validate);
        form.render();

        var E = window.wangEditor;
        var editor = new E('#editor');
        // 或者 var editor = new E( document.getElementById('editor') )
        editor.create();

        editor.txt.html(project.projectContent);

        $("#experiment_table").attr("ts-selected",project.courseId);

        tableSelect.render({
            elem: '#experiment_table',	//定义输入框input对象 必填
            checkedKey: 'courseId', //表格的唯一建值，非常重要，影响到选中状态 必填
            searchKey: 'courseName',	//搜索输入框的name值 默认keyword
            searchPlaceholder: '请输入实验课程',	//搜索输入框的提示文字 默认关键词搜索
            table: {	//定义表格参数，与LAYUI的TABLE模块一致，只是无需再定义表格elem
                url: ctx + 'course/select/course',
                cols: [
                    [
                        { type: 'radio' },
                        {field: 'courseName', title: '课程名称', minWidth: 100},
                        {field: 'deptNameList', title: '班级名称列表', align: 'center', width: 300},
                    ]
                ]
            },
            done: function (elem, data) {
                //选择完后的回调，包含2个返回值 elem:返回之前input对象；data:表格返回的选中的数据 []
                //拿到data[]后 就按照业务需求做想做的事情啦~比如加个隐藏域放ID...
                var NEWJSON = [];
                layui.each(data.data, function (index, item) {
                    NEWJSON.push(item.courseName);
                    $("#experimentId").val(item.courseId);
                });
                elem.val(NEWJSON.join(","))
            }
        });


        initUserValue();
        function initUserValue() {
            form.val("course-update-form", {
                "projectName": project.projectName,
                "state": project.state,
                "projectId":project.projectId
            });
        }
        form.on('submit(user-add-form-submit)', function (data) {
            data.field.projectContent = editor.txt.text();
            febs.post(ctx + 'experimentProject/update', data.field, function () {
                layer.closeAll();
                febs.alert.success('修改实验项目成功！');
                $('#febs-user').find('#query').click();
            });
            return false;
        });
    });
</script>